package com.ccjq.shosestore.web.controller.member;

import com.ccjq.shosestore.member.service.UserService;
import com.ccjq.shosestore.member.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "UserExistCheckServlet")
/**
 * 用户名是否存在校验
 */
public class UserExistCheckServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        System.out.println("====> 用户名注册重名检查... ");
        boolean result = userService.existx(username);
        if (result)
        {
            System.out.println(" ====> 用户名" + username +"已被注册");
        }else
        {
            System.out.println(" ====> 用户名" + username  +"可以注册");
        }
        PrintWriter out = response.getWriter();
        String jieguo = "{\"code\":"+result+"}";
        out.write(jieguo);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request, response);
    }
}
